﻿using System;
using System.Data;
using System.Collections.Generic;

namespace BLL.SysManage
{
    public class T_PUB_DICTIONARY
    {
        private readonly DALL.SysManage.T_PUB_DICTIONARY dal = new DALL.SysManage.T_PUB_DICTIONARY();
        public T_PUB_DICTIONARY()
        { }

        #region 判断此名称是否存在
        /// <summary>
        /// 判断此名称是否存在
        /// </summary>
        /// <param name="ParentID"></param>
        /// <param name="Name"></param>
        /// <returns></returns>
        public bool IsExistName(int ParentID, string Name)
        {
            return dal.IsExistName(ParentID, Name);
        }
        #endregion

        #region 获取同一父结点的子结点
        /// <summary>
        /// 获取同一父结点的子结点
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public DataTable GetParentOfChildList(int ID)
        {
            string strWhere = "FLAG = 1";
            if (!string.IsNullOrEmpty(ID.ToString()))
            {
                strWhere += string.Format(" and PARENT_ID = '{0}'", ID);
            }
            strWhere += string.Format(" order by ORDER_ID");
            return dal.GetParentOfChildList(strWhere);
        }
        #endregion

        #region 修改结点序号
        /// <summary>
        /// 修改结点序号
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="OrderID"></param>
        /// <returns></returns>
        public bool UpdateOrderID(int ID, int OrderID)
        {
            return dal.UpdateOrderID(ID, OrderID);
        }
        #endregion


        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteByFlag(int ID)
        {

            return dal.DeleteByFlag(ID);
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList()
        {
            string strWhere = " FLAG = 1 order by ORDER_ID ";
            return dal.GetList(strWhere);
        }

        /// <summary>
        /// 获得服务地址
        /// </summary>
        /// <param name="strBranchID"></param>
        /// <param name="strName"></param>
        /// <returns></returns>
        public List<Model.SysManage.T_PUB_DICTIONARY> GetAddress(string strBranchID, string strName)
        {
            string strWhere = string.Format("  PARENT_ID=(select id from T_PUB_DICTIONARY where Field='{0}')", strBranchID);
            if (strName!="")
            {
                strWhere = strWhere + " and NAME like '%"+strName+"%'"; 
            }
            return dal.GetListArray(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.SysManage.T_PUB_DICTIONARY> GetListArray(string strWhere)
        {
            return dal.GetListArray(strWhere);
        }


        #region  Method
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.SysManage.T_PUB_DICTIONARY model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.SysManage.T_PUB_DICTIONARY model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {

            return dal.Delete(ID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.SysManage.T_PUB_DICTIONARY GetModel(int ID)
        {

            return dal.GetModel(ID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.SysManage.T_PUB_DICTIONARY> GetModelList(string strWhere)
        {
            return dal.GetListArray(strWhere);
        }
        #endregion
    }
}
